<template>
  <div id="menu_id">
    <div class="menu_top">
      <p class="menu_note">
        注:
        <br />1.增加的新栏目为当前栏目下一行
        <br />2.修改完的栏目一行需保存后提交审批才能生效
      </p>
      <div class="menu_add">
        <el-button size="mini" round @click="add_open">增加</el-button>
      </div>
    </div>

    <el-table
      :data="menu_list"
      style="width: 100%"
      row-key="id"
      border
      lazy
      :tree-props="{children: 'children', hasChildren: 'hasChildren'}"
    >
      <el-table-column prop="id" label="编号"></el-table-column>
      <el-table-column prop="title" label="栏目名称"></el-table-column>
      <el-table-column prop="icon" label="栏目图标" v-slot="$props">
        <template>
          <i :class="$props.row.icon"></i>
        </template>
      </el-table-column>
      <el-table-column prop="url" label="栏目地址"></el-table-column>
      <el-table-column prop="status" label="状态" v-slot="$props">
        <template>
          <el-button v-if="$props.row.status === 0" size="mini" type="danger" plain round>已禁用</el-button>
          <el-button v-else-if="$props.row.status === 1" size="mini" type="success" plain round>已启用</el-button>
        </template>
      </el-table-column>
      <el-table-column prop="address" label="操作" v-slot="$props">
        <el-button size="mini" round @click="setFore($props.row)">修改</el-button>
        <template>
          <el-button size="mini" round @click="del($props.row.id)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
  <Addmenu ref="menu_ref" :isShow='isShow' :menu_list='menu_list' @reload_list='reload_list'></Addmenu>
  </div>
</template>

<script>

import { mapActions, mapState } from "vuex";
import Addmenu from '../views/Addmenu.vue'
export default {
  data() {
    return {
      isShow:{ flig :false}
    };
  },
  created() {
    this.MenuActions();
  },
  computed: {
    ...mapState({ menu_list: state => state.MenuStore.menu_list })
  },
  methods: {
      reload_list(){
            this.MenuActions();
      },
      setFore(obj){
          this.isShow.flig =true

          this.$refs.menu_ref.setFore(obj)
      },
    ...mapActions("MenuStore", ["MenuActions"]),
     //删除
    del(id) {
      this.$confirm("此操作将永久删除该文件, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      })
        .then(() => {
          this.$http.post("/menudelete", { id }).then(res => {
            if(res.code ==200){
               this.MenuActions();
            }
          });
         
          this.$message({
            type: "success",
            message: "删除成功!"
          });
           
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消删除"
          });
        });
    },
    add_open(){
        this.isShow.flig =true
    }
  },
  components:{
      Addmenu
  }
  
};
</script>

<style>
#menu_id .menu_top {
  display: flex;
  justify-content: space-between;
}
#menu_id .menu_note {
  font-size: 12px;
  color: #c4c4c4;
  text-align: left;
}
#menu_id .menu_add > button {
  width: 80px;
  color: #ff5d3e;
  background-color: white;
  text-align: center;
}
</style>